package com.honey.mybatis.generator;

import com.honey.compilation.java.AbstractJavaCompilation;
import com.honey.compilation.java.ClassDecoration;
import com.honey.compilation.java.Clazz;
import com.honey.compilation.java.JavaVisibility;
import com.honey.core.compiler.CompilationException;
import com.honey.core.dbmapping.introspect.IntrospectSchema;
import com.honey.core.dbmapping.introspect.IntrospectSchemaColumn;
import com.honey.core.types.FullyQualifiedJavaType;

public abstract class AbstractClass extends AbstractMybatis{
	
	/** 空字符串数组 */
	protected static final String[] EMPTY_STRING_ARRAY =new String[0];
	
	/** 默认 */
	protected static final FullyQualifiedJavaType[] DEFAULT_IMPLEMENTS =new FullyQualifiedJavaType[0];
	
	/** 数据库结构  */
	protected IntrospectSchema introspectSchema ;
	
	/** 数据库结构包含的列  */
	protected IntrospectSchemaColumn introspectSchemaColumn;
	
	/**
	 * 慎用默认的构造函数
	 */
	protected AbstractClass(){
	}
	
	/**
	 * 构造函数
	 * @param clazz
	 * @param belongPlugin
	 * @param introspectSchema
	 * @param introspectSchemaColumn
	 */
	protected AbstractClass(
			MybatisPlugin belongPlugin,
			IntrospectSchema introspectSchema,
			IntrospectSchemaColumn introspectSchemaColumn
			) {
		super(belongPlugin);
		this.introspectSchema = introspectSchema;
		this.introspectSchemaColumn = introspectSchemaColumn;
	}
	
	public final AbstractJavaCompilation createJavaCompilation() throws CompilationException{
		AbstractJavaCompilation answer = getAbstractJavaCompilation();
		if(answer != null){
			answer.setClassDecoration(getDecoration());
			answer.addAnnotation(getAnnotation());
			answer.addClassComment(getJavaDoc());
			answer.setSuperClass(getSuperClass());
			answer.addSuperInterface(getImplements());
			answer.setGeneric(getGeneric());
		}
		return answer ;
	}
	
	/**
	 * 类名称
	 * @return
	 */
	protected abstract FullyQualifiedJavaType getType();
	
	/**
	 * 类型
	 * @return
	 * @throws CompilationException
	 */
	protected AbstractJavaCompilation getAbstractJavaCompilation() throws CompilationException{
		return new Clazz(getType());
	}
	
	/**
	 * 属性修饰,默认使用public修饰.
	 * @return
	 * @throws CompilationException 
	 */
	protected ClassDecoration getDecoration() throws CompilationException{
		return new ClassDecoration(JavaVisibility.PUBLIC);
	}
	
	/**
	 * 注释
	 * @return
	 */
	protected String[] getJavaDoc(){
		return EMPTY_STRING_ARRAY;
	}
	
	/**
	 * 方法注解,默认为空.
	 * @return
	 */
	protected String[] getAnnotation(){
		return EMPTY_STRING_ARRAY;
	}
	
	/**
	 * 接口类
	 * @return
	 */
	protected FullyQualifiedJavaType[] getImplements(){
		return DEFAULT_IMPLEMENTS;
	}
	
	/**
	 * 父类
	 * @return
	 */
	protected FullyQualifiedJavaType getSuperClass(){
		return null;
	}
	
	/**
	 * 泛型
	 * @return
	 */
	protected FullyQualifiedJavaType getGeneric(){
		return null;
	}
}